package com.lk.config;

import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import reactor.core.publisher.Mono;

import java.util.Objects;

/**
 * 根据ip进行限流
 *
 * @author : com.com.lk
 * @date 2021/11/21 18:40
 **/
@Configuration(proxyBeanMethods = false)
public class GatewayConfig {

    @Bean
    public KeyResolver ipKeyResolver() {
        return (exchange) -> Mono.just(Objects.requireNonNull(exchange.getRequest().getRemoteAddress()).getHostName());
    }
}
